import logging

import allure
import pymysql
import requests

from config.config import *


@allure.step("2: 发送HTTP请求")
def send_http_request(**request_data):
    res = requests.request(**request_data)
    logging.info(f"2.发送HTTP请求，响应文本为：{res.text}")
    allure.attach(f"{res.text}", name="http请求响应文本")
    return res

def get_jdbc_conn():
    return pymysql.connect(host=DB_HOST,
                           port=DB_PORT,
                           user=DB_USER,
                           password=DB_PASSWORD,
                           database=DB_NAME,
                           charset=DB_CHARSET,
                           autocommit=True)

def send_jdbc_query(sql, index=0):
    # 设置index的默认值为0

    conn = get_jdbc_conn()
    cursor = conn.cursor()
    cursor.execute(sql)
    result = cursor.fetchone()
    cursor.close()
    conn.close()
    return result[index]


